<?php require_once('Connections/locamedicadmin.php'); ?>

<?php include('userValidation.php'); ?>

<?php require_once('functions.php'); ?>

<?php

$currentPage = $_SERVER["PHP_SELF"];

$filterValue = "";
$category = "";
$filter = "";



$maxRows_manufacturers = 20;
$pageNum_manufacturers = 0;
if (isset($_GET['pageNum_manufacturers'])) {
  $pageNum_manufacturers = $_GET['pageNum_manufacturers'];
}
$startRow_manufacturers = $pageNum_manufacturers * $maxRows_manufacturers;

mysql_select_db($database_locamedicadmin, $locamedicadmin);
$query_manufacturers = "SELECT * from csre_manufacture where 1 = 1 ";

if ((isset($_POST['search']) || isset($_GET['search']))) {

	if (isset($_POST['filter'])) { $filter = addslashes($_POST['filter']); } else { $filter = addslashes($_GET['filter']); }
	if (isset($_POST['filterValue'])) { $filterValue = addslashes($_POST['filterValue']); } else { $filterValue = addslashes($_GET['filterValue']); }

	if ($filterValue != "") {
		$where = "";
		if ($filter == "name") {
			$where = " and name_FR like '%" . $filterValue . "%' ";
		} else if ($filter == "num") {
			$where = "and manu_num like '%" . $filterValue . "%' ";
		}
	
		$query_manufacturers = $query_manufacturers . $where;
	}
}



$query_limit_manufacturers = sprintf("%s LIMIT %d, %d", $query_manufacturers, $startRow_manufacturers, $maxRows_manufacturers);

$manufacturers = mysql_query($query_limit_manufacturers, $locamedicadmin) or die(mysql_error());
$row_manufacturers = mysql_fetch_assoc($manufacturers);

if (isset($_GET['totalRows_manufacturers'])) {
  $totalRows_manufacturers = $_GET['totalRows_manufacturers'];
} else {
  $all_manufacturers = mysql_query($query_manufacturers);
  $totalRows_manufacturers = mysql_num_rows($all_manufacturers);
}
$totalPages_manufacturers = ceil($totalRows_manufacturers/$maxRows_manufacturers)-1;

$queryString_manufacturers = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_manufacturers") == false && 
        stristr($param, "totalRows_manufacturers") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_manufacturers = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_manufacturers = sprintf("&totalRows_manufacturers=%d%s", $totalRows_manufacturers, $queryString_manufacturers);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Locamedic CSRE Admin</title>
<link href="locamedicadmin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="page">

	<?php include('sidebar.php'); ?>
	
	<!-- end sidebar -->
	<div id="content">
		<div align="center"><img src="images/page_image_5.jpg" alt="" /></div>
	  <div class="boxed">
		<h1 class="title2">Manufacture List</h1>
	
		<table>
			<tr>
				<td>
					<form action="manufacture_list.php" method="post">
						<input type="hidden" value="search" name="search" />
						<table cellpadding="5" class="text">
							<tr>
								<td width="150">Rechercher pour:</td>
								<td width="150">Par:</td>
							</tr>
							<tr>
								<td><input type="text" name="filterValue" id="filterValue" value="<?php echo $filterValue; ?>"  />
									</td>
								<td>
									<select style="width: 180px;" class="text" name="filter" id="filter">
										<option <?php if ("name" == $filter) { echo "selected=\"selected\""; } ?> value="name">Nom Manufacture</option>
										<option <?php if ("num" == $filter) { echo "selected=\"selected\""; } ?> value="num"># Manufacture</option>
									</select>
								</td>
							</tr>
							
							<tr>
								<td colspan="3">												
									<div class="botonera">
										<input type="submit" value="Rechercher" />
									</div>
								</td>
							</tr>
						</table>
					</form>
				</td>
			</tr>
		</table>
		

		<?php if (isset($_GET['manufactureused'])) { ?>		
		<table>
			<tr>
				<td>
					<table>
						<tr>
							<td width="30">
								<img src="images/redCross.png" />
							</td>
							<td>
								Cannot delete manufacture selected because is assigned to one or more products.
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<?php } ?>
		<?php if ($totalRows_manufacturers > 0) { ?>
		<table cellpadding="5" cellspacing="0">
		  <thead>
		    <td>Name</td>
			<td># Manufacture</td>
			<td width="5%"></td>
			<td width="5%"></td>
		 </thead>
		  <?php do { ?>
			<tr>
			  <td><?php echo $row_manufacturers['name_FR']; ?></td>
			  <td><?php echo $row_manufacturers['manu_num']; ?></td>
			  <td align="center">
				<a href="manufacture_edit.php?manufactureid=<?php echo $row_manufacturers['manufacture_id']; ?>">
					<img src="images/1307905892_desktop.png" alt="Modifier" border="0" />
				</a>
			  </td>
			  <td align="center">
				<a href="manufacture_delete.php?manufactureid=<?php echo $row_manufacturers['manufacture_id']; ?>"
					onclick="return confirm('Etes-vous sûr de vouloir supprimer ce registre?');">
					<img src="images/1307905898_edit-trash.png" alt="Supprimer" border="0" />
				</a>
			  </td>
			</tr>
			<?php } while ($row_manufacturers = mysql_fetch_assoc($manufacturers)); ?>
		</table>
		<table>
			<tr>
				<td align="center">
					Rows <?php echo ($startRow_manufacturers + 1) ?> to <?php echo min($startRow_manufacturers + $maxRows_manufacturers, $totalRows_manufacturers) ?> of <?php echo $totalRows_manufacturers ?>
				</td>
			</tr>
		</table>
		       

		
		<table border="0" width="50%" align="center">
          <tr>
            <td width="23%" align="center"><?php if ($pageNum_manufacturers > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_manufacturers=%d%s", $currentPage, 0, $queryString_manufacturers); ?>"><img src="images/resultset_first.png" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="31%" align="center"><?php if ($pageNum_manufacturers > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_manufacturers=%d%s", $currentPage, max(0, $pageNum_manufacturers - 1), $queryString_manufacturers); ?>"><img src="images/resultset_previous.png" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_manufacturers < $totalPages_manufacturers) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_manufacturers=%d%s", $currentPage, min($totalPages_manufacturers, $pageNum_manufacturers + 1), $queryString_manufacturers); ?>"><img src="images/resultset_next.png" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_manufacturers < $totalPages_manufacturers) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_manufacturers=%d%s", $currentPage, $totalPages_manufacturers, $queryString_manufacturers); ?>"><img src="images/resultset_last.png" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
          </tr>
        </table>
		<?php } else { ?>
		<table>
			<tr>
				<td>No manfucatures found</td>
			</tr>
		</table>
		<?php } ?>
        <div class="botonera">
			<input type="button" onclick="window.location='manufacture_add.php';" value="Add manufacture" />
		</div>
		
	  </div>
  </div>
	<!-- end content -->
	<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->

<?php include('footer.php'); ?>

</body>
</html>
<?php
mysql_free_result($manufacturers);
?>